﻿#region "Copyright (C) Lenny Granovsky. 2005-2013"
//This program is free software distribute under the terms of the GNU General Public License as published by
//the Free Software Foundation. Please read AssemblyInfo.cs file for more information.
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Web.Enhancements.Rest.Filters
{
    /// <summary>
    /// <para>The interface that Attribute must impelement in order to be able to serve as custom attribute 
    /// for custom filter to the REST service method processing.</para>
    /// </summary>
    public interface IWebRestFilterAttribute
    {
        System.Type FilterType { get; }
        IWebRestFilter CreateFilter();
        /// <summary>
        /// Gets or sets the priority for the filter. By default priority is set to MaxValue of an Byte type that ensures the lowest priority. 
        /// </summary>
        byte Priority { get; }
    }

    /// <summary>
    /// <para>Attribute that allows to set a custom filter to the REST service method processing.</para>
    /// <para>This attribute is an optional.</para>
    /// </summary>
    [Serializable()]
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
    public class WebRestFilterAttribute : Attribute, IWebRestFilterAttribute
    {
        public WebRestFilterAttribute()
        {
            this.Priority = byte.MaxValue;
        }

        public virtual System.Type FilterType { get; set; }
        public virtual IWebRestFilter CreateFilter()
        {
            return (IWebRestFilter)Activator.CreateInstance(this.FilterType);
        }
        /// <summary>
        /// Gets or sets the priority for the filter. By default priority is set to MaxValue of an Byte type that ensures the lowest priority. 
        /// </summary>
        public byte Priority { get; set; }
    }
}
